home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 026a / lbl_new1.zip / LBL_NEW.COD next >
Text File  |  1991-07-17  |  28KB  |  1,251 lines

  1. //
  2. // Module Name: LABEL.COD
  3. // Description: Define label program structure.
  4. //
  5.  
  6. Label (.lbg) Program Template
  7. -----------------------------
  8. Version 1.1e
  9. Ashton-Tate (c) 1987
  10.  
  11. {include "label.def";
  12.  include "builtin.def";
  13.  //
  14.  // Enum string constants for international translation
  15.  // 
  16.  enum wrong_class = "Can't use LABEL.GEN on non-label objects.  ",
  17.       label_empty = "Label design was empty.  ",
  18.      more_samples = "Do you want more samples? (Y/N)";
  19.  //
  20.  if frame_class != label then
  21.    pause(wrong_class + any_key);
  22.    return 0;
  23.  endif
  24.  
  25.  //---------------------------
  26.  // Declare working variables
  27.  //---------------------------
  28.  var lblname,       // Name of label file program
  29.      lblpath,       // Path to write label file
  30.      default_drive, // dBASE default drive
  31.      crlf,          // line feed
  32.      line,          // Line counter for outputing number of "?'s"
  33.      isfirst,       // Logical work variable
  34.      mrows,         // Number of rows that the label uses
  35.      mcolumns,      // Number of columns in label
  36.      lbl_vspace,    // Lines between labels
  37.      lbl_wide,      // Label width
  38.      lbl_hspace,    // Number of spaces between labels 
  39.      lbl_offset,    // Label left offset
  40.      lbl_top,       // Label top margin
  41.      lbl_bottom,    // Label bottom margin
  42.      lbl_advance,   // Label forms advance  (linefeed or formfeed)
  43.      lbl_widow,     // Determine whether a label will fit on a page
  44.      lbl_copies,    // Number of labels to replicate
  45.      numflds,       // Number of fields used in label
  46.      style,         // Style attribute assigned to the field/text
  47.     current_column, // Current column number
  48.      first_combine, // text or field is first in the chain of combined data
  49.      combine,       // combine fields flag
  50.      new_line,      // is the next field on a new line
  51.  i, j, x, temp, ni, // temporary usage variables
  52.      first_item,    // relative element number when repeating columns
  53.      item_number,   // current item number
  54.      count,         // number of text and field items
  55.     last_row,
  56.     temp_row,
  57.    current_row,
  58.   previous_row,
  59.    blank_line,
  60.   printed_lines,
  61.  previous_element,
  62. number_of_blankable_lines,
  63.  current_element,
  64.     response,
  65.    long_line,       // calculated expression possibly exceeds line
  66.  left_delimiter,
  67.  right_delimiter,
  68.    delimit_flag
  69. ;
  70.  //-------------------------------------------------
  71.  // Assign starting values to some of the variables
  72.  //-------------------------------------------------
  73.  crlf = chr(10);
  74.  current_element=2;
  75.  item_number = isfirst = mcolumns = first_combine = new_line = 1;
  76.  count = line = mrows = numflds = current_column = combine = long_line = 0;
  77.  lbl_vspace = nul2zero(LABEL_VSPACE);
  78.  lbl_wide = LABEL_WIDE;
  79.  lbl_hspace = nul2zero(LABEL_HSPACE);
  80.  lbl_offset = nul2zero(LABEL_LMARG);
  81.  lbl_advance = lbl_bottom = lbl_top = 0;
  82.  lbl_copies  = lbl_widow = 1;
  83.  
  84.  blank_line = 1;
  85.  current_row = 0;
  86.  previous_row = -1;
  87.  printed_lines = 0;
  88.  previous_element = 0;
  89.  number_of_blankable_lines=0;
  90.  left_delimiter="\""
  91.  right_delimiter="\""
  92.  delimit_flag=0;
  93.  
  94.  foreach ELEMENT ecursor
  95.    if COUNTC(ecursor) > 1 && !eoc(ecursor) then
  96.      temp_row = previous_row = current_row = nul2zero(Row_Positn);
  97.      do while !eoc(ecursor)
  98.        if Row_Positn > previous_row then
  99.          number_of_blankable_lines=number_of_blankable_lines+blank_line;
  100.          blank_line=1;
  101.          previous_element=0;
  102.          previous_row=Row_Positn;
  103.          ++printed_lines;
  104.        endif
  105.        if blank_line then
  106.          if FLD_VALUE_TYPE == 78 then
  107.            if not AT("Z",FLD_PICFUN) then
  108.              blank_line=0;
  109.            endif
  110.          else
  111.            if Text_Item && !previous_element then
  112.              blank_line=0;
  113.            endif
  114.            if ELEMENT_TYPE == @Fld_Element && FLD_VALUE_TYPE != 67 then
  115.              blank_line=0;
  116.            endif
  117.          endif
  118.        endif
  119.        if ELEMENT_TYPE == @Fld_Element && FLD_VALUE_TYPE == 67 ||
  120.        (FLD_VALUE_TYPE == 78 && AT("Z",FLD_PICFUN)) then
  121.          previous_element=1;
  122.        else
  123.          previous_element=0;
  124.        endif            ++ecursor;
  125.      enddo
  126.      number_of_blankable_lines=number_of_blankable_lines+blank_line;
  127.      ++printed_lines;
  128.      --ecursor;
  129.      previous_row=Row_Positn+1;
  130.      last_row=Row_Positn;
  131.    endif
  132.  next
  133.  blank_line=0;
  134.  
  135.  default_drive = STRSET(_defdrive);
  136.  lblname = FRAME_PATH + NAME;
  137.  lblpath = FRAME_PATH;
  138.  if not FILEOK(lblname) then
  139.    if FILEDRIVE(NAME) || !default_drive then
  140.      lblname=NAME;
  141.      if FILEDRIVE(NAME) then
  142.        lblpath=FILEDRIVE(NAME)+":"+FILEPATH(NAME);
  143.      else
  144.        lblpath=FILEPATH(NAME);
  145.      endif
  146.    else
  147.      lblname=default_drive + ":" + NAME;
  148.      lblpath=default_drive + ":";
  149.    endif
  150.  endif
  151.  
  152.  if not CREATE(lblname+".LBG") then;
  153.    PAUSE(fileroot(lblname)+".LBG"+read_only+any_key);
  154.    return 0;
  155.  endif
  156.  
  157. if getenv("DTL_LBLOPT") then
  158.   cursor_pos(0,0);
  159.   cput(" Layout   Dimensions   Fields   Words   Go To   Print   Exit ");
  160.   cursor_pos(1,10);
  161.   cput("╔═════════════════════════╗");
  162.   cursor_pos(2,10);
  163.   cput("║  Top Margin     { 0}    ║");
  164.   cursor_pos(3,10);
  165.   cput("║  Bottom Margin  { 0}    ║");
  166.   cursor_pos(4,10);
  167.   cput("║  Advance by  DEFAULT    ║");
  168.   cursor_pos(5,10);
  169.   cput("║  Widow checking  YES    ║");
  170.   cursor_pos(6,10);
  171.   cput("║  Replicate      { 1}    ║");
  172.   cursor_pos(7,10);
  173.   cput("║         < OK >          ║");
  174.   cursor_pos(8,10);
  175.   cput("╚═════════════════════════╝");
  176.  
  177.   extended_label_options();
  178. endif
  179. }
  180. * Program............: {cap_first(fileroot(lblname))}.LBG
  181. * Date...............: {LTRIM(SUBSTR(DATE(),1,8))}
  182. * Version............: dBASE IV, Label {FRAME_VER}.1
  183. *
  184. * Label Specifics:
  185. *   Wide - {lbl_wide}
  186. *   Tall - {label_tall}
  187. *   Indentation - {nul2zero(label_lmarg)}
  188. *   Number across - {label_nup}
  189. *   Space between - {lbl_hspace}
  190. *   Lines between - {lbl_vspace}
  191. *   Blankable lines - {number_of_blankable_lines}
  192. *   Print formatted - {printed_lines}
  193. *
  194. PARAMETER ll_sample
  195. *-- Set printer variables for this procedure only
  196. PRIVATE {if lbl_advance then}_padvance, {endif}_peject, _wrap
  197.  
  198. *-- Test for End of file
  199. IF EOF()
  200.    RETURN
  201. ENDIF
  202.  
  203. IF SET("TALK")="ON"
  204.    SET TALK OFF
  205.    gc_talk="ON"
  206. ELSE
  207.    gc_talk="OFF"
  208. ENDIF
  209. gc_space = SET("SPACE")
  210. SET SPACE OFF
  211. gc_time=TIME()      && system time for predefined field
  212. gd_date=DATE()      && system date  "    "    "     "
  213. gl_fandl=.F.        && first and last record flag
  214. gl_prntflg=.T.      && Continue printing flag
  215. gn_column=1
  216. gn_copies=1
  217. gn_element=0
  218. gn_line=1
  219. gn_memowid=SET("MEMOWIDTH")
  220. SET MEMOWIDTH TO 254
  221. gn_page=_pageno     && capture page number for multiple copies
  222. {if lbl_advance then}
  223. {  case lbl_advance of}
  224. {  1:}
  225. _padvance="LINEFEEDS"
  226. {  2:}
  227. _padvance="FORMFEED"
  228. {  endcase}
  229. {endif}
  230. _plineno=0
  231. _wrap = .F.
  232.  
  233. *-- Setup Environment
  234. ON ESCAPE DO Prnabort
  235. {if lbl_top || lbl_bottom || lbl_advance then}
  236. gn_atline=_plength - {lbl_bottom+1}*_pspacing
  237. ON PAGE AT LINE gn_atline \
  238. {  if lbl_top then}
  239. DO Pagebrk
  240. {  else}
  241. EJECT PAGE
  242. {  endif}
  243. {endif}
  244.  
  245. {numflds=FRAME_NUM_OF_FIELDS;}
  246. {if LABEL_NUP > 1 then}
  247. *-- Initialize array(s) for {LABEL_NUP} across labels
  248. DECLARE isfound[{LABEL_NUP-1}]
  249. {  if numflds then}
  250. DECLARE tmp4lbl[{LABEL_NUP-1},{numflds}]
  251. {  endif}
  252. {endif}
  253. {//if number_of_blankable_lines then}
  254. DECLARE gn_line2[{label_nup}]
  255. {//endif}
  256.  
  257. PRINTJOB
  258.  
  259. {x=0;}
  260. {foreach FLD_ELEMENT k}
  261. //
  262. // only if there is a fieldname assigned to the calculated field
  263. //
  264. {if FLD_FIELDTYPE == Calc_data && FLD_FIELDNAME then}
  265. {  if !x then}
  266. *-- Initialize calculated variables.
  267. {  endif}
  268. {lower(FLD_FIELDNAME)}=\
  269. {case FLD_VALUE_TYPE of}
  270. {68: // Date   }CTOD(SPACE(8))
  271. {70: // Float  }FLOAT(0)
  272. {76: // Logical}.F.
  273. {78: // Numeric}INT(0)
  274. {otherwise:}""
  275. {endcase}
  276. {  ++x;}
  277. {endif}
  278. {next k;}
  279.  
  280. *-- set page number for multiple copies
  281. _pageno=gn_page
  282. {if lbl_top then}
  283. DO WHILE _plineno < {lbl_top}
  284.    ?
  285. ENDDO
  286. {endif}
  287.  
  288. IF ll_sample
  289.    DO Sample
  290.    IF LASTKEY() = 27
  291.       RETURN
  292.    ENDIF
  293. ENDIF
  294. DO WHILE FOUND() .AND. .not. EOF() .AND. gl_prntflg
  295. {LMARG(4);}
  296. {if LABEL_NUP > 1 then}
  297. {isfirst=1;}
  298. {x=1;}
  299. STORE .F. TO \
  300. {init_array:}
  301. {if isfirst then}
  302. {  isfirst=0;}
  303. {else}
  304. ,\
  305. {endif}
  306. isfound[{x}]\
  307. {++x;}
  308. {if x < LABEL_NUP then goto init_array endif}
  309.  
  310. {x=0;}
  311. {i=1;}
  312. {arcopy:}
  313. {  if x then}
  314. IF FOUND() .AND. .NOT. EOF()
  315. {    LMARG(7);}
  316. {  endif}
  317. {  calcflds();}
  318. //
  319. {foreach FLD_ELEMENT i}
  320. tmp4lbl[{x+1},{i}]=\
  321. {case FLD_FIELDTYPE of}
  322. {Tabl_data:}
  323. {  if FLD_VALUE_TYPE == 77 then}
  324. MLINE({cap_first(FLD_FIELDNAME)},1)
  325. {  else}
  326. {    cap_first(FLD_FIELDNAME)}
  327.  
  328. {  endif}
  329. {Calc_data:}
  330. {  if FLD_FIELDNAME then}
  331. {    lower(FLD_FIELDNAME)}
  332.  
  333. {  else}
  334. {    foreach FLD_EXPRESSION exp in i}
  335. {      FLD_EXPRESSION}\
  336. {    next}
  337.  
  338. {  endif}
  339. {Pred_data:}
  340. {  case FLD_PREDEFINE of}
  341. {  0: // Date}
  342. gd_date
  343. {  1: // Time}
  344. gc_time
  345. {  2: // Recno}
  346. RECNO()
  347. {  3: // Pageno}
  348. _pageno
  349. {  endcase}
  350. {endcase}
  351. {next i;}
  352. //
  353. {  if x then}
  354. isfound[{x}]=.T.
  355. {  endif}
  356. {  if lbl_copies then}
  357. IF gn_copies >= {lbl_copies}
  358.   gn_copies=1
  359.   CONTINUE
  360. ELSE
  361.   gn_copies=gn_copies+1
  362. ENDIF
  363. {  else}
  364. CONTINUE
  365. {  endif}
  366. {  if x then}
  367. {    LMARG(4);}
  368. ENDIF
  369. {  endif}
  370. {  ++x;}
  371. {  if x < LABEL_NUP-1 then
  372.      goto arcopy;
  373.    endif
  374. }
  375. IF FOUND() .AND. .NOT. EOF()
  376. {LMARG(7);}
  377. {calcflds();}
  378. isfound[{x}]=.T.
  379. {LMARG(4);}
  380. ENDIF
  381. {else}
  382. {calcflds();}
  383. {endif}
  384.  
  385. {x=0;
  386.  do while x < temp_row}
  387. ?
  388. {  ++x;
  389.  enddo
  390. }
  391. gn_line={temp_row}
  392. *-- Check for blank lines
  393. DO Chk4null WITH {temp_row}, {last_row+1}, {(last_row-temp_row+1)*label_nup}
  394.  
  395. DO WHILE gn_line < {label_tall+lbl_vspace}
  396.    ?
  397.    gn_line=gn_line+1
  398. ENDDO
  399. {  if lbl_copies then}
  400. IF gn_copies >= {lbl_copies}
  401.   gn_copies=1
  402.   CONTINUE
  403. ELSE
  404.   gn_copies=gn_copies+1
  405. ENDIF
  406. {  else}
  407. CONTINUE
  408. {  endif}
  409. {if (lbl_top || lbl_bottom) && lbl_widow then}
  410. {  if LABEL_TALL + lbl_vspace - 1 then}
  411. IF .NOT. EOF() .AND. _plineno+{LABEL_TALL + lbl_vspace - 1} > gn_atline
  412.    EJECT PAGE
  413. ENDIF
  414. {  endif}
  415. {endif}
  416. {LMARG(1);}
  417. ENDDO
  418.  
  419. IF .NOT. gl_prntflg
  420.    SET MEMOWIDTH TO gn_memowid
  421.    SET SPACE &gc_space.
  422.    SET TALK &gc_talk.
  423.    ON ESCAPE
  424.    RETURN
  425. ENDIF
  426.  
  427. {if lbl_top || lbl_bottom || lbl_advance then}
  428. ON PAGE
  429. {endif}
  430.  
  431. ENDPRINTJOB
  432.  
  433. {if lbl_top || lbl_bottom || lbl_advance then}
  434. IF _plineno <> 0
  435.    EJECT PAGE
  436. ENDIF
  437. {endif}
  438.  
  439. SET MEMOWIDTH TO gn_memowid
  440. SET SPACE &gc_space.
  441. SET TALK &gc_talk.
  442. ON ESCAPE
  443. RETURN
  444. * EOP: {cap_first(fileroot(lblname))}.LBG
  445.  
  446. PROCEDURE Prnabort
  447. gl_prntflg=.F.
  448. RETURN
  449. * EOP: Prnabort
  450.  
  451. //
  452. // Main loop (inner loop to handles fields on each line by # of columns)
  453. //
  454. {foreach ELEMENT k}
  455. {  if ELEMENT_TYPE == @Band_Element then}
  456. {    ++k; ++item_number;}
  457. {    if eoc(k) then}
  458. {      exit;}
  459. {    endif}
  460. {    temp_row=Row_Positn;}
  461. {  endif}
  462. {  ++count;}
  463. {  LMARG(1);}
  464. {  blank_line=0;}
  465. //
  466. {
  467.    if number_of_blankable_lines then
  468.  
  469.      long_line=0;
  470.      blank_line=1;
  471.      current_element=COUNTC(k);
  472.      previous_element=0;
  473.      previous_row=Row_Positn;
  474.  
  475.      do while !eoc(k);
  476.        if Row_Positn > previous_row then
  477.          exit
  478.        endif
  479.        if blank_line then
  480.          if FLD_VALUE_TYPE == 78 then
  481.            if not AT("Z",FLD_PICFUN) then
  482.              blank_line=0;
  483.            endif
  484.          else
  485.            if Text_Item && !previous_element then
  486.              blank_line=0;
  487.            endif
  488.            if ELEMENT_TYPE == @Fld_Element && FLD_VALUE_TYPE != 67 then
  489.              blank_line=0;
  490.            endif
  491.          endif
  492.        endif
  493.        if !blank_line then
  494.          exit
  495.        endif
  496.        if ELEMENT_TYPE == @Fld_Element && FLD_VALUE_TYPE == 67 ||
  497.        (FLD_VALUE_TYPE == 78 && AT("Z",FLD_PICFUN)) then
  498.          previous_element=1;
  499.        else
  500.          previous_element=0;
  501.        endif
  502.        ++k;
  503.      enddo
  504.      if eoc(k) then
  505.        --k;
  506.      endif
  507.  
  508.      do while COUNTC(k) > current_element;
  509.        --k;
  510.      enddo
  511.  
  512.    endif}
  513. //
  514. //---------------------
  515. // Process blank lines
  516. //---------------------
  517. {  line=temp_row+1;}
  518. {  do while line < Row_Positn}
  519. {    x=1;}
  520. {    do while x <= LABEL_NUP}
  521. FUNCTION ___{line}{x}
  522. ll_output=.T.
  523. RETURN .F.
  524.  
  525. {      ++x;}
  526. {    enddo}
  527. {    ++line;}
  528. {  enddo}
  529. //--------------------
  530. // End of blank lines
  531. //--------------------
  532. //
  533. {  mrows = 0;}
  534. {  first_item = item_number;}
  535. {  line = temp_row;}
  536. //
  537. {  repeat:}
  538. //
  539. {  if new_line then}
  540. FUNCTION ___{nul2zero(Row_Positn)}{mrows+1}
  541. lc_ret=.F.
  542. {    if mrows then}
  543. *-- Column {mrows+1}
  544. IF isfound[{mrows}]
  545. {LMARG(4);}
  546. {    endif}
  547. {    if blank_line then}
  548. {      if mrows then}
  549. {        conditional_if_for_blank_line(k,7);}
  550. {      else}
  551. {        conditional_if_for_blank_line(k,4);}
  552. {      endif}
  553. {    else}
  554. ll_output=.T.
  555. {    endif}
  556. {    if first_combine then}
  557. _pcolno = {Col_Positn+lbl_offset+(mrows*(lbl_wide+lbl_hspace))}
  558. {    endif}
  559. ?? \
  560. {  else}
  561. {    if long_line then}
  562. ?? \
  563. {      long_line=0;}
  564. {    else}
  565. ,\
  566. {    endif}
  567. {  endif}
  568. //
  569. {ni=0;}
  570. {  case ELEMENT_TYPE of}
  571. //
  572. {  @Text_Element:}
  573. //
  574. {x=Col_Positn;}
  575. {i=LEN(Text_Item);}
  576. {if i == 237 then}
  577. {  foreach Text_Item fcursor in k}
  578. {    if ni then}
  579. {      i=i+LEN(Text_Item);}
  580. {      temp=Text_Item;}
  581. {    endif}
  582. {    ++ni;}
  583. {  next}
  584. {endif}
  585. {current_column=x+i;}
  586. //
  587. {  @Fld_Element:}
  588. //
  589. {x=Col_Positn;}
  590. {i=FLD_REPWIDTH;}
  591. {if i > 237 then}
  592. {  foreach FLD_TEMPLATE fcursor in k}
  593. {    if ni then}
  594. {      temp=FLD_TEMPLATE;}
  595. {    endif}
  596. {    ++ni;}
  597. {  next}
  598. {endif}
  599. {current_column=x+i;}
  600. //
  601. {  endcase}
  602. //
  603. // is the next element on the same line
  604. //
  605. {  line=Row_Positn;}
  606. {  ++k;}
  607. {  if (not EOC(k)) && line == Row_Positn then}
  608. {    new_line=0;}
  609. //
  610. // is the next element flush with previous element
  611. //
  612. {    if current_column == Col_Positn then}
  613. {      combine=1;}
  614. {    else}
  615. {      combine=0;}
  616. {    endif}
  617. {  else}
  618. {    new_line=1;}
  619. {  endif}
  620. {  --k;}
  621. //-----------------------------------------------
  622. // Determine what type of data we are processing
  623. //-----------------------------------------------
  624. {  case ELEMENT_TYPE of}
  625. //
  626. {  @Text_Element:}
  627. //
  628. {if blank_line then}
  629. IIF(LEN(TRIM(\
  630. {  --k;}
  631. {  if FLD_VALUE_TYPE == 78 then}
  632. TRANSFORM(\
  633. {  endif}
  634. {  if mrows+1 < LABEL_NUP then}
  635. tmp4lbl[{mrows+1},{mcolumns-1}] \
  636. {  else}
  637. {    putfld(k);}
  638. {  endif}
  639. {  if FLD_VALUE_TYPE == 78 then}
  640. ,"@{FLD_PICFUN}")\
  641. {  endif}
  642. {  ++k;}
  643. )) > 0,\
  644. {  long_line=1;
  645.  endif}
  646. //
  647. {if substr(Text_Item,1,1) == "\"" then
  648.    left_delimiter = "["
  649.    right_delimiter = "]"
  650.    delimit_flag = 1;
  651.  endif}
  652. {if i > 70 then}
  653. ;
  654. {  seperate(Text_Item);}
  655. {  if ni then}
  656. + {left_delimiter}{temp}{right_delimiter};
  657. {  endif}
  658. {else}
  659. {left_delimiter}{Text_Item}{right_delimiter} \
  660. {endif}
  661. //
  662. {if blank_line then}
  663. ,"" ) \
  664. {endif}
  665. //
  666. {if delimit_flag then
  667.    left_delimiter="\""
  668.    right_delimiter="\""
  669.    delimit_flag=0;
  670.  endif}
  671. {  @Fld_Element:}
  672. //
  673. {    if mrows+1 < LABEL_NUP then}
  674. tmp4lbl[{mrows+1},{mcolumns}] \
  675. {    else}
  676. {      putfld(k);}
  677. {    endif}
  678. {    ++mcolumns;}
  679. {  endcase}
  680. //
  681. {  if ELEMENT_TYPE == @Fld_Element then}
  682. //
  683. {    if !FLD_FIELDTYPE || FLD_FIELDTYPE == Calc_data || 
  684.         (FLD_FIELDTYPE == Pred_data && FLD_PREDEFINE > 1) then}
  685. //
  686. {      if FLD_VALUE_TYPE == 67 then
  687.          j=FLD_TEMPLATE+temp;
  688.          if FLD_LENGTH == FLD_REPWIDTH && j == REPLICATE("X",FLD_LENGTH) then
  689.            j="";
  690.          endif
  691.        else
  692.          j="1";
  693.        endif}
  694. //
  695. {      if FLD_PICFUN || j then}
  696. PICTURE \
  697. {      endif}
  698. //
  699. {      if FLD_PICFUN then}
  700. "@{FLD_PICFUN}\
  701. {        if j then}
  702.  \
  703. {        else}
  704. " \
  705. {        endif}
  706. {      endif}
  707. //
  708. {      if j then}
  709. {        if i > 70 then}
  710. {          if FLD_PICFUN then}
  711. "+;
  712. {          else}
  713. ;
  714. {          endif}
  715. {          seperate(FLD_TEMPLATE);}
  716. {          if ni then}
  717. + "{temp}";
  718. {          endif}
  719. {        else}
  720. {          if !FLD_PICFUN then}
  721. "\
  722. {          endif}
  723. {FLD_TEMPLATE}" \
  724. {        endif}
  725. {      endif}
  726. {    endif}
  727. //
  728. {  endif}
  729. //
  730. {  if FLD_STYLE then}
  731. {    style=getstyle(FLD_STYLE);}
  732. STYLE "{style}" \
  733. {  endif}
  734. {  if first_combine then}
  735. AT {Col_Positn+lbl_offset+(mrows*(lbl_wide+lbl_hspace))} \
  736. {    if combine then}
  737. {      first_combine=0;}
  738. {    endif}
  739. {  else}
  740. {    if not combine then first_combine=1; endif}
  741. {  endif}
  742. //
  743. // position to next element
  744. //
  745. {  temp_row=Row_Positn;}
  746. {  ++k; ++item_number;}
  747. //
  748. {  if !new_line || (!EOC(k) && temp_row == Row_Positn) then
  749.      if !new_line then}
  750. {      if long_line then}
  751. ,
  752. {      else}
  753. ;
  754. {      endif}
  755. {    else}
  756. ,
  757. {      long_line=0;}
  758. {    endif
  759.      if !EOC(k) then
  760.        goto repeat;
  761.      endif}
  762. {  else}
  763. {    long_line=0;}
  764. {  endif}
  765. //
  766. {  combine=0;}
  767. {  first_combine=1;}
  768. //
  769. {  if LABEL_NUP-1 > mrows then}
  770. ,
  771. {    if blank_line && mrows then}
  772. {      LMARG(4);}
  773. {    else}
  774. {      LMARG(1);}
  775. {    endif}
  776. {    if blank_line then}
  777. {      if temp_row != last_row then}
  778. ELSE
  779.    lc_ret=.T.
  780. {      endif}
  781. ENDIF
  782. {    endif}
  783. {    if mrows then}
  784. {      LMARG(1);}
  785. ENDIF
  786. {    endif}
  787. RETURN lc_ret
  788.  
  789. {    ++mrows;}
  790. {    do while item_number > first_item}
  791. {      --k; --item_number;}
  792. {      if ELEMENT_TYPE == @Fld_Element then}
  793. {        --mcolumns;}
  794. {      endif}
  795. {    enddo}
  796. {    new_line=1;}
  797. {    goto repeat;}
  798. {  else}
  799.  
  800. {    if mrows then}
  801. {      LMARG(4);}
  802. {    else}
  803. {      LMARG(1);}
  804. {    endif}
  805. {    if blank_line then}
  806. {      if temp_row != last_row then}
  807. ELSE
  808.    lc_ret=.T.
  809. {      endif}
  810. ENDIF
  811. {    endif}
  812. {    if mrows then}
  813. {      LMARG(1);}
  814. ENDIF
  815. {    endif}
  816. RETURN lc_ret
  817.  
  818. {    mrows=0;}
  819. {    --k; --item_number;}
  820. {  endif}
  821. //
  822. {next k;}
  823.  
  824. PROCEDURE Chk4null
  825. *-- Parameters:
  826. *
  827. *-- 1) line number on the design surface
  828. *-- 2) maximum number of printable lines
  829. *-- 3) parameter 2 times number of labels across
  830. *
  831. PARAMETERS ln_line, ln_lastrow, ln_element
  832. gn_element=0
  833. {    x=1;
  834.      do while x <= label_nup}
  835. gn_line2[{x}]=ln_line
  836. {      ++x;
  837.      enddo}
  838. lc_temp=SPACE(7)
  839. ll_output=.F.
  840. DO WHILE gn_element < ln_element
  841.    gn_column=1
  842.    ll_output=.F.
  843.    DO WHILE gn_column <= {label_nup}
  844.       IF gn_line2[gn_column] < ln_lastrow
  845.          lc_temp=LTRIM(STR(gn_line2[gn_column]))+LTRIM(STR(gn_column))
  846.          DO WHILE ___&lc_temp.()
  847.             gn_element=gn_element+1
  848.             gn_line2[gn_column]=gn_line2[gn_column]+1
  849.             lc_temp=LTRIM(STR(gn_line2[gn_column]))+LTRIM(STR(gn_column))
  850.          ENDDO
  851.          gn_element=gn_element+1
  852.          gn_line2[gn_column]=gn_line2[gn_column]+1
  853.       ENDIF
  854.       gn_column=gn_column+1
  855.    ENDDO
  856.    IF ll_output
  857.      ?
  858.      gn_line=gn_line+1
  859.    ENDIF
  860. ENDDO
  861. RETURN
  862. * EOP: Chk4null
  863. {if lbl_top then}
  864.  
  865. PROCEDURE Pagebrk
  866. EJECT PAGE
  867. DO WHILE _plineno < {lbl_top}
  868.    ?
  869. ENDDO
  870. RETURN
  871. * EOP: Pagebrk
  872. {endif}
  873.  
  874. PROCEDURE Sample
  875. PRIVATE x,y,choice
  876. DEFINE WINDOW w4sample FROM 15,20 TO 17,60 DOUBLE
  877. choice="Y"
  878. x=0
  879. DO WHILE choice = "Y"
  880.    y=0
  881.    DO WHILE y < {LABEL_TALL}
  882.       x=0
  883.       DO WHILE x < {LABEL_NUP}
  884.          ?? REPLICATE("X",{LABEL_WIDE})\
  885. {if LABEL_HSPACE then}
  886. +SPACE({LABEL_HSPACE})
  887. {else}
  888.  
  889. {endif}
  890.          x=x+1
  891.       ENDDO
  892.       ?
  893.       y=y+1
  894.    ENDDO
  895. {if LABEL_VSPACE then}
  896.    x=0
  897.    DO WHILE x < {LABEL_VSPACE}
  898.       ?
  899.       x=x+1
  900.    ENDDO
  901. {endif}
  902.    ACTIVATE WINDOW w4sample
  903.    @ 0,3 SAY "{more_samples}";
  904.    GET choice PICTURE "!" VALID choice $ "NY"
  905.    READ
  906.    DEACTIVATE WINDOW w4sample
  907.    IF LASTKEY() = 27
  908.       EXIT
  909.    ENDIF
  910. ENDDO
  911. RELEASE WINDOW w4sample
  912. RETURN
  913. * EOP: Sample
  914. {if !count then pause(label_empty + any_key); endif}
  915. {return 0;}
  916. //--------------------------------
  917. // End of main template procedure
  918. // User defined function follows
  919. //--------------------------------
  920. {
  921.  define getstyle(mstyle);
  922.   var outstyle; 
  923.   outstyle="";
  924.   if Bold        & mstyle then outstyle=outstyle+"B"; endif
  925.   if Italic      & mstyle then outstyle=outstyle+"I"; endif
  926.   if Underline   & mstyle then outstyle=outstyle+"U"; endif
  927.   if Superscript & mstyle then outstyle=outstyle+"R"; endif
  928.   if Subscript   & mstyle then outstyle=outstyle+"L"; endif
  929.   if User_Font   & mstyle then 
  930.     if  1 & mstyle then outstyle=outstyle+"1"; endif
  931.     if  2 & mstyle then outstyle=outstyle+"2"; endif
  932.     if  4 & mstyle then outstyle=outstyle+"3"; endif
  933.     if  8 & mstyle then outstyle=outstyle+"4"; endif
  934.     if 16 & mstyle then outstyle=outstyle+"5"; endif
  935.   endif
  936. return outstyle;
  937. enddef;
  938. }
  939. {define putfld(cursor);
  940.  var value,value2;
  941.  value=cursor.FLD_FIELDTYPE;}
  942. {       if mrows+1 < LABEL_NUP then}
  943. tmp4lbl[{mrows+1},{mcolumns}] \
  944. {       else}
  945. {case value of}
  946. {Tabl_data:}
  947. {  if cursor.FLD_VALUE_TYPE == 77 then}
  948. MLINE({cap_first(cursor.FLD_FIELDNAME)},1)\
  949. {  else}
  950. {    cap_first(cursor.FLD_FIELDNAME)}\
  951. {  endif}
  952. {Calc_data:}
  953. {  if cursor.FLD_FIELDNAME then}
  954. {    lower(cursor.FLD_FIELDNAME)}\
  955. {  else}
  956. {    foreach FLD_EXPRESSION exp in cursor}
  957. {      FLD_EXPRESSION}\
  958. {    next}
  959.  ;
  960. {    long_line=1;}
  961. {  endif}
  962. {Pred_data:}
  963. {  value2=cursor.FLD_PREDEFINE;}
  964. {  case value2 of}
  965. {  0: // Date}
  966. gd_date\
  967. {  1: // Time}
  968. gc_time\
  969. {  2: // Recno}
  970. RECNO()\
  971. {  3: // Pageno}
  972. _pageno\
  973. {  endcase}
  974. {endcase}
  975.  \
  976. {       endif}
  977. {return;
  978. enddef;
  979. }
  980. {
  981.  define conditional_if_for_blank_line(cursor2, page_offset);
  982.  var field_flag, current_row;
  983. }
  984. *-- Test for blank line
  985. IF LEN(TRIM( \
  986. {
  987.        current_element=COUNTC(cursor2);
  988.        current_row=cursor2.Row_Positn;
  989.        do while !eoc(cursor2) && cursor2.Row_Positn == current_row}
  990. {        if cursor2.ELEMENT_TYPE == @Fld_element then
  991.            if field_flag then}+ \
  992. {          else
  993.              field_flag=1;
  994.            endif
  995.          endif
  996.          if cursor2.FLD_VALUE_TYPE == 78 then}
  997. TRANSFORM(\
  998. {          putfld(cursor2);}
  999. ,"\
  1000. {          if cursor2.FLD_PICFUN then}
  1001. @{cursor2.FLD_PICFUN} \
  1002. {          endif}
  1003. {cursor2.FLD_TEMPLATE}") \
  1004. {//
  1005.          else
  1006.            if cursor2.ELEMENT_TYPE == @Fld_element then
  1007.              putfld(cursor2);
  1008.            endif
  1009.          endif
  1010.          if cursor2.ELEMENT_TYPE == @Fld_element then
  1011.            ++mcolumns;
  1012.          endif
  1013.          ++cursor2;
  1014.        enddo
  1015.        do while eoc(cursor2) || COUNTC(cursor2) > current_element;
  1016.          --cursor2;
  1017.          if cursor2.ELEMENT_TYPE == @Fld_element then
  1018.            --mcolumns;
  1019.          endif
  1020.        enddo}
  1021. )) > 0
  1022. {LMARG(page_offset);}
  1023. ll_output=.T.
  1024. {  return;
  1025.  enddef
  1026. }
  1027. {define calcflds();}
  1028. {foreach FLD_ELEMENT k}
  1029. {  if FLD_FIELDNAME && FLD_FIELDTYPE == Calc_data then}
  1030. {lower(FLD_FIELDNAME)}=\
  1031. {foreach FLD_EXPRESSION j in k}
  1032. {FLD_EXPRESSION}
  1033. {next}
  1034.  
  1035. {  endif}
  1036. {next k;}
  1037. {return;}
  1038. {enddef}
  1039. {
  1040.  define seperate(string);
  1041.  var x,y,length;
  1042.  x=1;
  1043.  length=LEN(string);
  1044.  moreleft:
  1045.  if x < length then
  1046.    if x != 1 then}
  1047. + \
  1048. {  endif
  1049.    if x+70 <= length then y=70; else y=length-x+1; endif}
  1050. "{SUBSTR(string,x,y)}";
  1051. {  x=x+70;
  1052.    goto moreleft;
  1053.  endif
  1054.  return;
  1055.  enddef
  1056. }
  1057. {
  1058.  define extended_label_options()
  1059.  var curopt,ikey,row,col,lval,rval;
  1060.  curopt=6;
  1061.  rval=0;
  1062.  do while rval != 1 && rval != 117
  1063.    if !rval then
  1064.      nmsg( "Position: "+chr(25)+chr(24)+
  1065.        "  Select: "+chr(17)+chr(196)+chr(217)+
  1066.        "  CTRL-END or ESC: All options are correct");
  1067.    endif
  1068.    case curopt of
  1069.    1:
  1070.      pmsg("Number of physical lines from top of form.");
  1071.      cursor_pos(2,30);
  1072.    2:
  1073.      pmsg("Number of physical lines from bottom of form.");
  1074.      cursor_pos(3,30);
  1075.    3:
  1076.      pmsg("Page advance using DEFAULT (Print Menu), LINE FEEDS or FORM FEED");
  1077.      cursor_pos(4,25);
  1078.    4:
  1079.      pmsg("Check whether a label will fit on the page or not.");
  1080.      cursor_pos(5,29);
  1081.    5:
  1082.      pmsg("Number of labels to replicate.");
  1083.      cursor_pos(6,30);
  1084.    6:
  1085.      pmsg("Accept current settings.");
  1086.      cursor_pos(7,21);
  1087.    endcase
  1088.    ikey=CGET(); rval=ikey >> 16; lval=ikey & 0xFFFF;
  1089.    if lval == 32 && (curopt == 3 || curopt == 4) then
  1090.      rval=13;
  1091.    endif
  1092.    case rval of
  1093.    13:
  1094. ;
  1095.      case curopt of
  1096.      1:
  1097.        lbl_top=enter_number(lbl_top,2);
  1098.        rval=0;
  1099.      2:
  1100.        lbl_bottom=enter_number(lbl_bottom,3);
  1101.        rval=0;
  1102.      3:
  1103.        lbl_advance=change_advance_by(lbl_advance);
  1104.      4:
  1105.        lbl_widow=change_widow(lbl_widow);
  1106.      5:
  1107.        lbl_copies=enter_number(lbl_copies,6)
  1108.        rval=0;
  1109.      6:
  1110.        rval=1;
  1111.      endcase
  1112. ;
  1113.    72:
  1114.      --curopt;
  1115.    80:
  1116.      ++curopt;
  1117.    endcase
  1118.    if curopt > 6 then
  1119.      curopt=1;
  1120.    endif
  1121.    if curopt < 1 then
  1122.      curopt=6;
  1123.    endif
  1124.  enddo
  1125.  cursor_pos(23,00);
  1126.  return;
  1127.  enddef
  1128.  
  1129.  define enter_number(number,row)
  1130.  var leftnum, rightnum, entry, rvalue, lvalue, tempnum;
  1131.  if number > 9 then
  1132.    leftnum=substr(str(number),1,1);
  1133.    rightnum=substr(str(number),2,1);
  1134.  else
  1135.    leftnum="0";
  1136.    rightnum=substr(str(number),1,1);
  1137.  endif
  1138.  nmsg("Increase or decrease: "+CHR(24)+CHR(25)+
  1139.    "  Accept: "+CHR(17)+CHR(196)+CHR(217)+
  1140.    "  Cancel: Esc");
  1141.  if row == 6 then
  1142.    pmsg("Specify the number of labels to replicate (1-99)");
  1143.    tempnum=1
  1144.  else
  1145.    pmsg("Specify the length of the margin in lines (0-99)");
  1146.    tempnum=0
  1147.  endif
  1148.  do while rvalue != 1 && rvalue != 13 && rvalue != 117
  1149.    entry=CGET(); rvalue=entry >> 16; lvalue=entry & 0xFFFF;
  1150.    if !rvalue then
  1151.      if lvalue > 47 && lvalue < 58 then
  1152.        leftnum=rightnum;
  1153.        rightnum=str(lvalue-48);
  1154.        cursor_pos(row,29);
  1155.        cput(leftnum+rightnum);
  1156.        cursor_pos(row,30);
  1157.        tempnum=(val(leftnum)*10) + val(rightnum);
  1158.      endif
  1159.    endif
  1160.    if rvalue == 72 || rvalue == 80 then
  1161.      case rvalue of
  1162.      72:
  1163.        tempnum=tempnum+1;
  1164.        if tempnum == 100 && row == 6 then
  1165.          tempnum=1;
  1166.        endif
  1167.      80:
  1168.        tempnum=tempnum-1;
  1169.        if tempnum == 0 && row == 6 then
  1170.          tempnum=tempnum-1;
  1171.        endif
  1172.      endcase
  1173.      if tempnum > 99 then
  1174.        tempnum=0
  1175.      endif
  1176.      if tempnum < 0 then
  1177.        tempnum=99;
  1178.      endif
  1179.      if tempnum > 9 then
  1180.        leftnum=substr(str(tempnum),1,1);
  1181.        rightnum=substr(str(tempnum),2,1);
  1182.      else
  1183.        leftnum="0";
  1184.        rightnum=substr(str(tempnum),1,1);
  1185.      endif
  1186.      cursor_pos(row,29);
  1187.      if !tempnum then
  1188.        cput(" 0");
  1189.      else
  1190.        if tempnum < 10 then
  1191.          cput(" ");
  1192.        endif
  1193.        cput(str(tempnum));
  1194.      endif
  1195.      cursor_pos(row,30);
  1196.    endif
  1197.  enddo
  1198.  if tempnum == 0 && row == 6 then
  1199.    leftnum=" ";
  1200.    rightnum="1";
  1201.  endif
  1202.  if rvalue != 1 then
  1203.    number=(val(leftnum)*10) + val(rightnum);
  1204.  endif
  1205.  cursor_pos(row,29);
  1206.  if !number then
  1207.    cput(" 0");
  1208.  else
  1209.    if number < 10 then
  1210.      cput(" ");
  1211.    endif
  1212.    cput(str(number));
  1213.  endif
  1214.  cursor_pos(row,30);
  1215.  return number;
  1216.  enddef
  1217.  
  1218.  define change_widow(woption)
  1219.  ++woption;
  1220.  if woption > 1 then
  1221.    woption=0;
  1222.  endif
  1223.  case woption of
  1224.  0:
  1225.    cput("NO ");
  1226.  1:
  1227.    cput("YES");
  1228.  endcase
  1229.  cursor_pos(5,29);
  1230.  return woption;
  1231.  enddef
  1232.  
  1233.  define change_advance_by(aoption)
  1234.  ++aoption;
  1235.  if aoption > 2 then
  1236.    aoption=0;
  1237.  endif
  1238.  case aoption of
  1239.  0:
  1240.    cput("DEFAULT   ");
  1241.  1:
  1242.    cput("LINE FEEDS");
  1243.  2:
  1244.    cput("FORM FEED ");
  1245.  endcase
  1246.  cursor_pos(4,25);
  1247.  return aoption;
  1248.  enddef
  1249. }
  1250. // EOP: LABEL.COD
  1251.